package org.fage.semples.service;

import java.util.ArrayList;
import java.util.List;

import org.fage.semples.dao.ExamScoreHiberanteDAO;
import org.fage.semples.dao.ExamSubjectHiberanteDAO;
import org.fage.semples.model.ExamScore;
import org.fage.semples.model.ExamScoreVO;
import org.fage.semples.model.ExamSubject;
import org.fage.semples.model.PagerModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ExamSubjectHiberanteServiceImpI implements ExamSubjectHiberanteService {

	@Autowired
	private ExamSubjectHiberanteDAO examSubjectHiberanteDAO;
	
	@Autowired
	private ExamScoreHiberanteDAO examScoreHiberanteDAO;
	
	@Override
	public PagerModel<ExamSubject> findAllByPage() {
		return examSubjectHiberanteDAO.findAllByPage();
	}
	
	@Override
	public List<String> getAllUserBySubjcet(String subId) {
		return examSubjectHiberanteDAO.getAllUserBySubjcet(subId);
	}

	
	@Override
	public ExamSubject getExamSubjectById(String subId) {
		return examSubjectHiberanteDAO.getExamSubjectById(subId);
	}

	@Override
	public List<ExamSubject> findAllExamSubject() {
		return examSubjectHiberanteDAO.findAllExamSubject();
	}

	@Override
	public void createExamSubject(ExamSubject examSubject) throws Exception {
		examSubjectHiberanteDAO.createExamSubject(examSubject);
	}

	@Override
	public void editExamSubject(ExamSubject examSubject) throws Exception {
		examSubjectHiberanteDAO.editExamSubject(examSubject);
	}

	@Override
	public void deleteExamSubject(String subId) throws Exception {
		examSubjectHiberanteDAO.deleteExamSubject(subId);
	}


	@Override
	public void saveSubjectStudent(List<String> list, Integer subjectId) {
		examSubjectHiberanteDAO.saveSubjectStudent(list,subjectId);
		
	}


	@Override
	public List<ExamScoreVO> getScoreBySubId(String subId) {
		List<ExamScore> examScoreList = examScoreHiberanteDAO.getScoreBySubId(subId);
		List<ExamScoreVO> examScoreVOList = new ArrayList<ExamScoreVO>();
		ExamScoreVO examScoreVO = null;
		for(ExamScore examScore:examScoreList){
			examScoreVO = new ExamScoreVO();
			BeanUtils.copyProperties(examScore, examScoreVO);
			examScoreVOList.add(examScoreVO);
		}
		return examScoreVOList;
	}

}
